package com.example.hetong_system.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.example.hetong_system.model.enums.AuditStatus;

import javax.persistence.*;

@Entity
@Table(name = "contract_clause")
public class ContractClause {
    @EmbeddedId
    private ContractClauseId id;

    // 使用@JsonBackReference标记关系的被动方，序列化时忽略此方向的引用
    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("contractId")
    @JoinColumn(name = "contract_id")
    @JsonBackReference
    private Contract contract;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("clauseId")
    @JoinColumn(name = "clause_id")
    private Clause clause;

    @Column(nullable = false)
    private String type = "INITIAL";

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AuditStatus legalAuditStatus = AuditStatus.PENDING;

    private String legalOpinion;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AuditStatus financeAuditStatus = AuditStatus.PENDING;

    private String financeOpinion;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AuditStatus customerAuditStatus = AuditStatus.PENDING;

    private String customerOpinion;

    // 构造方法
    public ContractClause() {}

    public ContractClause(Contract contract, Clause clause, String type) {
        this.contract = contract;
        this.clause = clause;
        this.type = type;
        this.id = new ContractClauseId(contract.getId(), clause.getId());
    }

    public String getFinanceOpinion() {
        return financeOpinion;
    }

    public void setFinanceOpinion(String financeOpinion) {
        this.financeOpinion = financeOpinion;
    }

    // getters and setters
    public ContractClauseId getId() {
        return id;
    }

    public void setId(ContractClauseId id) {
        this.id = id;
    }

    public Contract getContract() {
        return contract;
    }

    public void setContract(Contract contract) {
        this.contract = contract;
        if (contract != null) {
            this.id.setContractId(contract.getId());
        }
    }

    public Clause getClause() {
        return clause;
    }

    public void setClause(Clause clause) {
        this.clause = clause;
        if (clause != null) {
            this.id.setClauseId(clause.getId());
        }
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public AuditStatus getLegalAuditStatus() {
        return legalAuditStatus;
    }

    public void setLegalAuditStatus(AuditStatus legalAuditStatus) {
        this.legalAuditStatus = legalAuditStatus;
    }

    public String getLegalOpinion() {
        return legalOpinion;
    }

    public void setLegalOpinion(String legalOpinion) {
        this.legalOpinion = legalOpinion;
    }

    public AuditStatus getFinanceAuditStatus() {
        return financeAuditStatus;
    }

    public void setFinanceAuditStatus(AuditStatus financeAuditStatus) {
        this.financeAuditStatus = financeAuditStatus;
    }

    public AuditStatus getCustomerAuditStatus() {
        return customerAuditStatus;
    }

    public void setCustomerAuditStatus(AuditStatus customerAuditStatus) {
        this.customerAuditStatus = customerAuditStatus;
    }

    public String getCustomerOpinion() {
        return customerOpinion;
    }

    public void setCustomerOpinion(String customerOpinion) {
        this.customerOpinion = customerOpinion;
    }
}